//
//  EnterpriseDynamicViewController.m
//  AnXin100
//
//  Created by 王合润 on 10/17/18.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "EnterpriseDynamicViewController.h"
#import "SDCycleScrollView.h"
#import "EnterpriseDynamicTableViewCell.h"
#import "NewsModel.h"
@interface EnterpriseDynamicViewController ()<UITableViewDelegate, UITableViewDataSource,SDCycleScrollViewDelegate>

@property (nonatomic, strong) UITableView *mainTable;
@property (nonatomic, strong) SDCycleScrollView *tableHeadImage;
@property (nonatomic, strong) NSMutableArray *arrayModel;
@end

@implementation EnterpriseDynamicViewController

- (void)viewDidLoad {

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [PublicMonMethods setupNavigationItems:self];
    [PublicMonMethods settitle:@"企业动态" viewController:self];
    [self.view addSubview:self.mainTable];
    [self getData];
}


#pragma lazy load
- (UITableView *)mainTable {
    if (!_mainTable) {
        
        _mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
        _mainTable.delegate = self;
        _mainTable.dataSource = self;
        _mainTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainTable.tableHeaderView = self.tableHeadImage;
        [_mainTable registerNib:[UINib nibWithNibName:@"EnterpriseDynamicTableViewCell" bundle:nil] forCellReuseIdentifier:@"EnterpriseDynamicTableViewCell"];
        
    }
    return _mainTable;
}

- (SDCycleScrollView *)tableHeadImage {
    if (!_tableHeadImage) {
        NSArray *imageNames = @[@"m1.jpeg",
                                @"m2.jpeg",
                                @"m3.jpeg",
                                @"m4.jpeg",
                                @"m5.jpeg" // 本地图片请填写全名
                                ];
        _tableHeadImage = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 180) shouldInfiniteLoop:YES imageNamesGroup:imageNames];
        _tableHeadImage.delegate = self;
        _tableHeadImage.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        _tableHeadImage.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    }
    return _tableHeadImage;
}

#pragma mark - UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrayModel.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    EnterpriseDynamicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EnterpriseDynamicTableViewCell"];
    return cell;
}

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - 获取数据
- (void)getData {
    
    [NetWorkHelp yl_postDataWith:@{@"demoSecondId" : _url_Id, @"pageSize" : @"10", @"pageNum" : @"1"} url:URL_SPLIT(URL_Interactive, URL_Interactive_News) success:^(id respose) {
        _arrayModel = [NewsModel mj_objectArrayWithKeyValuesArray:respose[@"body"][@"news"]];
        [_mainTable reloadData];
    } failure:^(NSError *error) {
        
    }];
}


@end
